package ch.exm.storm.query.selection;

import ch.exm.storm.conditions.arguments.EvaluatedArgument;

public class EvaluatedRelationalSelection extends EvaluatedSelection {
	
	private EvaluatedArgument evaluatedArgument;
	
	public EvaluatedRelationalSelection(Selection selection, EvaluatedArgument evaluatedArgument) {
		super(selection, evaluatedArgument.getSourceArgument());
		this.evaluatedArgument = evaluatedArgument;
	}
	
	public String getSelectionStatement() {
		return evaluatedArgument.isFullyEvaluated() ? 
				selection.getSelectionStatement(evaluatedArgument.getEvaluatedPart()) : 
				evaluatedArgument.getEvaluatedPart();
	}
	
	public boolean isFullyEvaluated() {
		return evaluatedArgument.isFullyEvaluated();
	}
	
	public Object applySelectionOn(Object source) {
		return partiallyEvaluated ? evaluatedArgument.evaluateNonRelationalPart(source) : super.applySelectionOn(source);
	}
	
	private boolean partiallyEvaluated = false;
	public void setAsPartiallyEvaluated() { partiallyEvaluated = true; }
	
	@Override
	public String toString() {
		return "select " + selection + " on " + evaluatedArgument;
	}
}
